﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.APP.Application.Command.Shop;
using Traceability.Domain;
using Traceability.ErrorCode;

namespace Traceability.APP.Controllers
{
    /// <summary>
    /// Api 控制器-商品管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {
        private readonly IMediator mediator;

        public ShopController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 商品信息显示
        /// </summary>
        /// <param name="comman"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<Shop_Model>>> ShopAll([FromQuery]GetShopAllComman comman)
        {
            return mediator.Send(comman);    
        }

        /// <summary>
        /// 商品信息的新增
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<Shop_Model>> ShopAdd(Shop_Model shop)
        { 
            GetAddShopCommand command = new GetAddShopCommand();
            command.SID = shop.SID; 
            command.Shop_Name = shop.Shop_Name;
            return await mediator.Send(command);
        }

    }
}
